#ifndef _bsp_key_h
#define _bsp_key_h

#include "main.h"
#include "gd32f30x.h"

/* 按键状态 */
enum key_state {
    RELEASE = 0,
    PRESSED = 1,
};

/* 按键事件 */
enum key_event {
    NONE = 0,
    CLICK = 1,
    DOUBLE_CLICK = 2,
    LONG_CLICK = 3,
    CONTINUE_TRIGGER = 4,
};

struct key_dev {
    uint8_t val[4];  //存最近4次的按键值
    enum key_state last_state;  //上次状态
    enum key_state cur_state;  //当前状态
    uint32_t pressed_time;  //按下计数
    uint32_t release_time;  //释放计数
    uint8_t wait_double_flag;  //等待双击标志
    uint8_t press_hold_flag;  //长按保持标志
    enum key_event key_event;
};

extern struct key_dev key0;

void key_val_get(void);
void key_event_get(void);
void key_event_handle(void);

#endif
